package com.ruoyi.project.business.controller;

import cn.mabach.business.entity.HomeAdvertiseEntity;
import cn.mabach.result.PageResult;
import cn.mabach.result.RS;
import com.ruoyi.project.business.feign.HomeAdvertiseServiceFeign;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import java.util.Arrays;
import java.util.List;
import java.util.Map;


/**
 * 首页轮播广告表
 *
 * @author chenshun
 * @email 176468159@qq.com
 * @date 2019-12-31 21:38:07
 */
@RestController
@RequestMapping("/home/advertise")
public class HomeAdvertiseController {
    @Autowired
    private HomeAdvertiseServiceFeign homeAdvertiseService;



    /**
        * 分页列表
        */
    @GetMapping(value = "/list")
    @PreAuthorize("@ss.hasPermi('sms:advertise:read')")
    public RS<PageResult<HomeAdvertiseEntity>> getList(@RequestParam(value = "name", required = false) String name,
                                                       @RequestParam(value = "type", required = false) Integer type,
                                                       @RequestParam(value = "endTime", required = false) String endTime,
                                                       @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                                                       @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize) {

        RS<PageResult<HomeAdvertiseEntity>> pageResultRS = homeAdvertiseService.queryPage(name, type,endTime,pageNum, pageSize);

        return pageResultRS;
    }



    /**
     * 根据ID获取信息
     */

    @GetMapping(value = "/{id}")
    @PreAuthorize("@ss.hasPermi('sms:advertise:read')")
    public RS<HomeAdvertiseEntity> getItem(@PathVariable("id") Long id) {
        return homeAdvertiseService.getByIdE(id);
    }





    /**
     * 根据id保存
     */
    @PostMapping(value = "/create")
    @PreAuthorize("@ss.hasPermi('sms:advertise:create')")
    public RS create(@RequestBody HomeAdvertiseEntity homeAdvertiseEntity) {

        RS rs = homeAdvertiseService.saveE(homeAdvertiseEntity);

        return rs;
    }



    /**
     * 根据id修改
     */
    @PostMapping(value = "/update/{id}")
    @PreAuthorize("@ss.hasPermi('sms:advertise:update')")
    public RS update(@PathVariable("id") Long id,
                     @Validated @RequestBody HomeAdvertiseEntity entity,
                     BindingResult result) {
        entity.setId(id);
        RS rs = homeAdvertiseService.updateByIdE(entity);

        return rs;
    }

    /**
       * 根据id集合删除
       */
    @PostMapping(value = "/delete")
    @PreAuthorize("@ss.hasPermi('sms:advertise:delete')")
    public RS deleteBatch(@RequestParam("ids") List<Long> ids) {
        RS rs = homeAdvertiseService.removeByIdsE(ids);
        return rs;
    }

    /**
         * 根据id删除
         */
    @RequestMapping(value = "/delete/{id}", method = RequestMethod.POST)
    @PreAuthorize("@ss.hasPermi('sms:advertise:delete')")
    public RS removeByIdE(@PathVariable Long id) {

        return homeAdvertiseService.removeByIdE(id);

    }

    /*
    * 修改上下线状态
    * */
    @PreAuthorize("@ss.hasPermi('sms:advertise:update')")
    @RequestMapping(value = "/update/status", method = RequestMethod.POST)
    public RS updateStatus(@RequestParam("id") Long id, @RequestParam("status") Integer status) {
       return homeAdvertiseService.updateStatus(id,status);
    }
}
